package com.szxy.miaosha.service.impl;

import com.szxy.miaosha.dao.UserDao;
import com.szxy.miaosha.domain.Users;
import com.szxy.miaosha.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Auther:wzer
 * @Date:2020/9/5
 * @Description:com.szxy.miaosha.service
 * @Version:1.0
 **/
@Service
public class UsersServiceImpl implements UsersService {


    @Autowired
    private UserDao userDao;

    @Override
    public List<Users> selectAllUsers() {
        return this.userDao.selectAll();
    }

    @Override
    public Users selectUserById(int id) {
        return this.userDao.selectUserById(id);
    }

    @Override
    @Transactional
    public boolean insertUser(Users user) {
        int i = this.userDao.insertUser(user);
        if (i > 0) {
            return true;
        }
        return false;
    }

    @Override
    @Transactional
    public boolean insertUser() {
        int i = this.userDao.insertUser(new Users(2, "word"));
        int j = this.userDao.insertUser(new Users(1, "word2"));
        if (i > 0 && j > 0) {
            return true;
        }
        return false;
    }
}
